package com.zhitong.ztblog.utils;

import sun.misc.BASE64Encoder;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5 {

//    密码加密
    public static String encoderByMD5(String password) throws Exception{
            MessageDigest md5=MessageDigest.getInstance("MD5");
            BASE64Encoder base64en = new BASE64Encoder();
            String newPW=base64en.encode(md5.digest(password.getBytes("utf-8")));
            return newPW;

    }

    public static boolean checkPW(String password,String encodePW) throws Exception{
        if (encoderByMD5(password).equals(encodePW)){
            return true;
        }else{
            return false;
        }
    }
}
